<template>
  <div id="app">
    <teleport to="body">
      <div v-if="modalShow" class="modal">
        <div>
          <button @click="closeModal" class="close-btn">关闭</button>
        </div>
      </div>
    </teleport>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";

export default defineComponent({
  props: {
    // 模态框显隐
    modalShow: Boolean,
  },
  emits: ["close-Modal"],
  setup(props, context) {
    /* 关闭按钮 */
    function closeModal() {
      context.emit("close-Modal");
    }
    return { closeModal };
  },
});
</script>

<style scoped>
.modal {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.modal div { 
  background-color: white;
  width: 350px;
  height: 300px;
  padding: 5px;
}

.close-btn {
    float: right;
}

.close-btn:hover {
    cursor: pointer;
}
</style>
